package com.hk.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: dpb
 * @date: 2022/3/28
 */
//@Component
public class MsgTtlQueueConfig {

    public static final String Y_DEAD_EXCHANGE = "Y";
    public static final String QC_QUEUE = "QC";

    //定义队列c 死信交换机
//    @Bean("queueC")
    public Queue queueC(){
        Map<String, Object> args = new HashMap<>(3);
        args.put("x-dead-letter-exchange",Y_DEAD_EXCHANGE);
        args.put("x-dead-letter-routing-key","YD");
        return QueueBuilder.durable(QC_QUEUE).withArguments(args).build();
    }

    //绑定队列c 与交换机X并指定routingKey
//    @Bean
    public Binding queueBindingX(@Qualifier("queueC") Queue queueC,
                                 @Qualifier("xExchange") DirectExchange xExchange){
        return BindingBuilder.bind(queueC).to(xExchange).with("XC");
    }
}
